package clusteringAlg;

import java.io.File;
import java.text.DecimalFormat;

public class SampleSelectorWorker {

	SamplesSelector samples = null;
	FaceDB db;
	ProcessImage StylePI;
	Algorithms alg;
	Long durationTime;
	
	/**
	 * @return the durationTime
	 */
	public Long getDurationTime() {
		return durationTime;
	}

	/**
	 * @param durationTime the durationTime to set
	 */
	public void setDurationTime(Long durationTime) {
		this.durationTime = durationTime;
	}

	/**
	 * @return the sample
	 */
	public SamplesSelector getSelector() {
		return samples;
	}

	/**
	 * @param sample the sample to set
	 */
	public void setSelector(SamplesSelector samples) {
		this.samples = samples;
	}

	/**
	 * @return the db
	 */
	public FaceDB getDb() {
		return db;
	}

	/**
	 * @param db the db to set
	 */
	public void setDb(FaceDB db) {
		this.db = db;
	}

	/**
	 * @return the stylePI
	 */
	public ProcessImage getStylePI() {
		return StylePI;
	}

	/**
	 * @param stylePI the stylePI to set
	 */
	public void setStylePI(ProcessImage stylePI) {
		StylePI = stylePI;
	}

	/**
	 * @return the alg
	 */
	public Algorithms getAlg() {
		return alg;
	}

	/**
	 * @param alg the alg to set
	 */
	public void setAlg(Algorithms alg) {
		this.alg = alg;
	}

	public SampleSelectorWorker() {
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @param p - osoba s fotografiami
	 * @param nCluster - pocet clustrov
	 * @param iteration - pocet iteracii
	 * @param pi - typ predspracovania obrazku pri inicializacii
	 */
	public void CreateSOM(Person p, int nClusters, int iteration, ProcessImage pi){
		this.samples = new MySelfOrganizingMap(p, nClusters, iteration, pi);
		this.alg = Algorithms.SOM;
		this.StylePI = pi;
	}
	
	/**
	 * @param p - osoba s fotografiami
	 * @param nCluster - pocet clustrov
	 * @param iteration - pocet iteracii
	 * @param pi - typ predspracovania obrazku pri inicializacii
	 */
	public void CreateKmeans(Person p, int nClusters, int iteration, ProcessImage pi ){
		this.samples = new KMeans(p, nClusters, iteration, pi);
		this.alg = Algorithms.Kmeans;
		this.StylePI = pi;
	}
	
	/**
	 * @param p - osoba s fotografiami
	 * @param nCluster - pocet clustrov
	 * @param iteration - pocet iteracii
	 * @param pi - typ predspracovania obrazku pri inicializacii
	 */
	public void CreateCmeans(Person p, int nClusters, int iteration, ProcessImage pi ){
		this.samples = new CMeans(p, nClusters, iteration, pi);
		this.alg = Algorithms.Cmeans;
		this.StylePI = pi;
	}
	
	/**
	 * @param p - osoba s fotografiami
	 * @param nCluster - pocet clustrov
	 * @param minPts - minimalny pocet bodov v clustri
	 * @param eps - velkost okolia
	 */
	public void CreateDBScan (Person p, int nClusters, int minPts ){
		this.samples = new DBScan(p, nClusters, minPts);
		this.alg = Algorithms.DBScan;
		this.StylePI = ProcessImage.UNDEFINED;
	}
	
	public void CreateDir(String dir){
		File f = new File(dir);
		
		if (!f.exists()) {
		    boolean result = f.mkdir();  

		     if(!result) {    
		       System.out.println("DIR not created"); 
		       CreateDir(f.getParentFile().getAbsolutePath());
		       CreateDir(dir);
		     }
		 }
	}
	
	public String CreatePath(String str){
		
		/*switch (this.db){
		case EURECOM:
			str += "/EURECOM";
			break;
		case PIE:
			str += "/PIE";
			break;
		default:
			break;
		}*/
		
		switch(this.alg){
		case Cmeans:
			str += "/Cmeans";
			break;
		case DBScan:
			str += "/DBScan";
			break;
		case Kmeans:
			str += "/Kmeans";
			break;
		case SOM:
			str += "/SOM";
			break;
		default:
			break;
		}
		
		switch(this.StylePI){
		case GAUSS_BLUR:
			str += "/GBlur";
			break;
		case GAUSS_NOISE:
			str += "/GNoise";
			break;
		default:
			break;
		}
		
		this.CreateDir(str);
		
		return str;
	}
	
	public String CreateLog(){
		
		String str = new String();
		
		switch(this.alg){
		case Cmeans:
			str += "Cmeans,";
			break;
		case DBScan:
			str += "DBScan,";
			break;
		case Kmeans:
			str += "Kmeans,";
			break;
		case SOM:
			str += "SOM,";
			break;
		default:
			str += " ,";
			break;
		}
		
		switch (this.db){
		case EURECOM:
			str += "EURECOM,";
			break;
		case PIE:
			str += "PIE,";
			break;
		default:
			str += " ,";
			break;
		}
		
		switch(this.StylePI){
		case GAUSS_BLUR:
			str += "GBlur,";
			break;
		case GAUSS_NOISE:
			str += "GNoise,";
			break;
		default:
			str += " ,";
			break;
		}
		
		/*Date date = new Date(this.getDurationTime());
		DateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS");
		String dateFormatted = formatter.format(date);*/
		
		double seconds = ((double)this.getDurationTime() / 1000000000);
		
		str+= new DecimalFormat("#.##########").format(seconds) + ",";
		
		for (Sample s : this.getSelector().GetClosestSamples()){
			str+= s.getPose() + ",";
		}
		
		return str;
	}

}
